package com.jqh.demo.controller;


import com.jqh.demo.entity.AclUser;
import com.jqh.demo.service.AclUserService;
import com.jqh.demo.utils.JwtUtils;
import com.jqh.demo.utils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/api/login")
@CrossOrigin
public class LoginController {
    @Autowired
    private AclUserService aclUserService;

    @ApiOperation("用户登陆,生成token返回给用户")
    @PostMapping("loginTo")
    public R login(@RequestBody AclUser aclUser) {
        R r=aclUserService.login(aclUser);
        return r;
    }

    @ApiOperation("根据token获取用户信息")
    @GetMapping("getUserInfoByToken")
    public R getUserInfoByToken(HttpServletRequest request){
        String userId = JwtUtils.getMemberIdByJwtToken(request);
        AclUser aclUser = aclUserService.getById(userId);
        return R.ok().data("userInfo",aclUser);
    }



}
